home *** CD-ROM | disk | FTP | other *** search
- Path: netnews1.apci.com!usenet
- From: wardmw@apci.com (Martin Ward)
- Newsgroups: comp.lang.c
- Subject: Re: Multiplication Problem - How to multiply really big numbers, and printing the answers out.
- Date: Thu, 01 Feb 1996 07:46:17 GMT
- Organization: Air Products Europe
- Message-ID: <4eprck$4o6@netnews1.apci.com>
- References: <4ep07m$4fn@newsbf02.news.aol.com>
- Reply-To: wardmw@apci.com
- NNTP-Posting-Host: p1862.apci.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- agent439@aol.com (Agent439) typed:
-
-
- >Here is the program
- >#include <math.h>
- >#include <stdio.h>
- >#include <time.h>
-
- >#define FALSE 0
- >#define TRUE !FALSE
-
- >float timer(int reset);
- >void main(){
- >
- > char a[100],b[100];
- > int i, j;
- > int x, y, z;
- > int size,truesize;
- > unsigned long pa,pb, c;
- >
- > a==NULL;
- > b==NULL;
- > printf("Enter the Multiplicand:");
- > gets(a);
- > while(a<0){
-
- You've defined a as a character array, so trying to check it's less than 0
- like this will fail. Try something like:
- while(a[0] == '-') {
-
- but you'll need to watch out for leading spaces.
-
-
- > printf("Positive Integers only please!");
- > printf("Enter the Multiplicand:");
- > gets(a);
- > }
- >
- > printf("Enter the Multiplier:");
- > gets(b);
- > while(b<0){
- Same problem as a above.
-
- > printf("Positive Integers only please!");
- > printf("Enter the Multiplier:");
- > gets(b);
- > }
- > size=0;
- > pa=0;
- > while(a[size] != 0){
- > size++;
- > }
- > size--;
- You could replace the above code with
- size = strlen(a);
- unless you're banned from using string functions.
-
- > truesize=size;
- > for(size==size;size>=0;size--){
- Shouldn't this be:
- for (size = size; size >= 0; size --) {
- ^
- One equals sign.
-
- > pa += (a[size]-48)*(pow(10,(truesize-size))); //change char to integer
- >value
- > }
- > size=0;
- > pb=0;
- > while(b[size] != 0){
- > size++;
- > }
- > size--;
- > truesize=size;
- > for(size==size;size>=0;size--){
- > pb += (b[size]-48)*(pow(10,(truesize-size))); //change char to
- >integer value
- > }
- > //timer(TRUE);
- > c=0;
- > c+=(pa);//Start C with the amount in pa
- > c*=(pb); //Multiply pa by the integer value of pb
- > printf("The product is =======> %i \n",c);
-
- I've not tried to compile your code, just had a glance through it, but it
- strikes me that here, you're trying to print out the product of two very large
- numbers. These number themselves can't be held in an integer variable, so
- there's no way the product can!
-
- HTH
-
- |\/|
-
-